package com.prs.crm.action.sys;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.domain.sys.VoteAdmin;
import com.prs.crm.service.sys.VoteAdminService;

public class VoteAdminAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private VoteAdmin voteAdmin;
	private VoteAdminService voteAdminService;
	private String serCode;
	public String getSerCode() {
		return serCode;
	}
	public void setSerCode(String serCode) {
		this.serCode = serCode;
	}
	public VoteAdmin getVoteAdmin() {
		return voteAdmin;
	}
	public void setVoteAdmin(VoteAdmin voteAdmin) {
		this.voteAdmin = voteAdmin;
	}
	public VoteAdminService getVoteAdminService() {
		return voteAdminService;
	}
	public void setVoteAdminService(VoteAdminService voteAdminService) {
		this.voteAdminService = voteAdminService;
	}
	
	@Action("editVoteAdmin")
	public String editVoteAdmin(){
		this.voteAdmin=this.getVoteAdminService().getVoteAdmin(serCode);
		return SUCCESS;
	}
	@Action(value="saveVoteAdmin",results={
			@Result(name="success",type="redirect",location="editVoteAdmin?serCode=${voteAdmin.getType()}"),
			@Result(name="error",type="redirect",location="editVoteAdmin?serCode=${voteAdmin.getType()}")
	})
	public String saveVoteAdmin(){
		VoteAdmin vote=this.getVoteAdminService().getVoteAdmin("vm01");
		if(vote==null){
			vote=new VoteAdmin();
			vote.setType("vm01");
			vote.setPersonName(voteAdmin.getPersonName());
			vote.setPersonNameId(voteAdmin.getPersonNameId());
			this.getVoteAdminService().save(vote);
		}
		else{
			this.getVoteAdminService().submit(vote);
		}
		voteAdmin=vote;
		return SUCCESS;
	}
}
